package com.example.rydwlib

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.baselib.WaterMarkBg
import com.example.baselib.activity.BaseActivity
import com.example.baselib.activity.BaseViewModelActivity
import com.example.baselib.constants.ARConstants
import com.example.baselib.databean.Unitinfo
import com.example.rydwlib.bean.RyNickBean
import kotlinx.android.synthetic.main.activity_rydw_main.*
@Route(path = ARConstants.APP_RYDW)
class RydwMainActivity : BaseViewModelActivity<RydwViewModel>() {
    override fun providerVMClass(): Class<RydwViewModel>? {
        return RydwViewModel::class.java
    }

    private val findNavController: NavController by lazy { Navigation.findNavController(this, R.id.rydw_nav_fragment) }
    override fun layoutResId(): Int=R.layout.activity_rydw_main

    override fun initView() {
        setToolbarMsg("人员定位")
        setToolbarColor(R.color.colorDBlue, R.color.colorWhite)
        setToolbarMenu(true, R.id.menu_rydw)
        rydw_bottom.itemIconTintList = null
        rydw_background.background = WaterMarkBg
        NavigationUI.setupWithNavController(
            rydw_bottom,
            findNavController
        )
        findNavController.addOnDestinationChangedListener { controller, destination, arguments ->
            when(destination.id){
                R.id.ryMainAlarmFragment,R.id.ryMainPersonFragment ->  rydw_bottom.visibility= View.GONE
                else ->  rydw_bottom.visibility= View.VISIBLE
            }
        }
    }

    override fun initData() {
        try {
            val map:HashMap<String,String> =HashMap()
            map["unitname"]=intent.getStringExtra("unitname")
            map["unitcode"]=intent.getStringExtra("unitcode")
            viewModel.setUnitInfo(map)
        } catch (e: Exception) {

        }
    }
    override fun backOnClick() {
        onBackPressed()
    }

    override fun onBackPressed() {
        when(findNavController.currentDestination?.id){
            R.id.ryMainAlarmFragment,R.id.ryMainPersonFragment -> findNavController.popBackStack()
            else -> finish()
        }

    }

}
